package com.tongle.frs.common.util;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumValidatorUtils
{
  public boolean isCrossing(double value, double max, double min)
  {
    boolean et = value <= max;

    boolean lt = value >= min;

    return (et) && (lt);
  }

  public static boolean isNumeric(String value)
  {
    if (StringUtils.isNotBlank(value)) {
      return StringUtils.isNumeric(value);
    }
    return false;
  }

  public static boolean isNotEmpty(Long value)
  {
    return (value != null) && (value.longValue() != 0L);
  }

  public boolean areNotEmpty(String[] values)
  {
    boolean result = true;
    for (String value : values) {
      result = (result) && (StringUtils.isNotBlank(value));
    }

    return result;
  }

  public boolean areIsNumber(Object[][] arrays)
  {
    boolean result = true;
    for (Object[] array : arrays) {
      result = (result) && (!ArrayUtils.isEmpty(array));
    }
    return result;
  }

  public static boolean isNumber(String num)
  {
    String rule = "^\\d+$";
    Pattern pattern = Pattern.compile(rule);
    Matcher m = pattern.matcher(num);
    return m.matches();
  }

  public static boolean isNumberAndDecimal(String num)
  {
    Pattern pattern = Pattern.compile("^\\d+$|^\\d+\\.\\d+$|-\\d+$");
    Matcher isNum = pattern.matcher(num);

    return isNum.matches();
  }

  public static boolean isFormatRight(String right, String rule)
  {
    Pattern pattern = Pattern.compile(rule);
    Matcher m = pattern.matcher(right);

    return m.matches();
  }

  public static String replaceBlank(String str)
  {
    String dest = "";
    if (str != null) {
      Pattern p = Pattern.compile("\\s*|\t|\r|\n");
      Matcher m = p.matcher(str);
      dest = m.replaceAll("");
    }
    return dest;
  }

  public static String removeAllBlank(String s)
  {
    String result = "";
    if ((null != s) && (!"".equals(s))) {
      result = s.replaceAll("[　*| *| *|//s*]*", "");
    }
    return result;
  }

  public static String trim(String s)
  {
    String result = "";
    if ((null != s) && (!"".equals(s))) {
      result = s.replaceAll("^[　*| *| *|//s*]*", "").replaceAll("[　*| *| *|//s*]*$", "");
    }
    return result;
  }
}